////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////
#include "otpch.h"
#include <iostream>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

#include "configserver.h"
#include "tools.h"

void ConfigServer::loadFromXml()
{	

	xmlDocPtr doc = xmlParseFile(getFilePath(FILE_TYPE_CONFIG, "config.xml").c_str());
	if(doc){
		xmlNodePtr root, p;
		unsigned long id = 0;
		root = xmlDocGetRootElement(doc);

		if(xmlStrcmp(root->name,(const xmlChar*)"configserver")){
			xmlFreeDoc(doc);
			return;
		}

		p = root->children;
		while(p){
			if(xmlStrcmp(p->name, (const xmlChar*)"config")){
				
				if(!readXMLInteger(p, "dataDirectory", getGlobalString))
				{
				 	std::cout << "[Error - ConfigServer::] Cannot load data durectory." << std::endl;
					return false;
				}
			}
			p = p->next;
		}
		xmlFreeDoc(doc);
	}
}
